package com.example.android.wearable.wear.wearaccessibilityapp.view;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.wear.widget.CurvingLayoutCallback;
import androidx.wear.widget.WearableLinearLayoutManager;
import androidx.wear.widget.WearableRecyclerView;

import com.example.android.wearable.wear.wearaccessibilityapp.AccessibilityActivity;
import com.example.android.wearable.wear.wearaccessibilityapp.AppItem;
import com.example.android.wearable.wear.wearaccessibilityapp.ControlsActivity;
import com.example.android.wearable.wear.wearaccessibilityapp.DialogsActivity;
import com.example.android.wearable.wear.wearaccessibilityapp.ListsActivity;
import com.example.android.wearable.wear.wearaccessibilityapp.MenuRecyclerViewAdapter;
import com.example.android.wearable.wear.wearaccessibilityapp.NotificationsActivity;
import com.example.android.wearable.wear.wearaccessibilityapp.ProgressActivity;
import com.example.android.wearable.wear.wearaccessibilityapp.R;
import com.example.android.wearable.wear.wearaccessibilityapp.ScalingScrollLayoutCallback;

import java.util.ArrayList;
import java.util.List;

public class AppFragment1 extends Fragment {

    private View mRootView;
    private Context mContext;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.activity_main, container, false);
        mContext = getContext();
        return mRootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        // Menu items
        List<AppItem> items = new ArrayList<AppItem>();
        items.add(
                new AppItem(
                        getString(R.string.lists), R.drawable.lists_circle, ListsActivity.class));
        items.add(
                new AppItem(
                        getString(R.string.dialogs),
                        R.drawable.dialogs_circle,
                        DialogsActivity.class));
        items.add(
                new AppItem(
                        getString(R.string.progress),
                        R.drawable.progress_circle,
                        ProgressActivity.class));
        items.add(
                new AppItem(
                        getString(R.string.controls),
                        R.drawable.controls_circle,
                        ControlsActivity.class));
        items.add(
                new AppItem(
                        getString(R.string.notifications),
                        R.drawable.notifications_circle,
                        NotificationsActivity.class));
        items.add(
                new AppItem(
                        getString(R.string.accessibility),
                        R.drawable.accessibility_circle,
                        AccessibilityActivity.class));

        MenuRecyclerViewAdapter appListAdapter = new MenuRecyclerViewAdapter(mContext, items);

        WearableRecyclerView recyclerView = mRootView.findViewById(R.id.main_recycler_view);

        // Customizes scrolling so items farther away form center are smaller.
     /*   ScalingScrollLayoutCallback scalingScrollLayoutCallback = new ScalingScrollLayoutCallback();
        recyclerView.setLayoutManager(
                new WearableLinearLayoutManager(mContext, new CurvingLayoutCallback(mContext)));*/
        recyclerView.setLayoutManager(new AppLayoutManager(mContext,new CurvingLayoutCallback1(mContext)));

        recyclerView.setEdgeItemsCenteringEnabled(true);
        recyclerView.setAdapter(appListAdapter);
    }
}
